﻿using System;
using System.Collections.Generic;
using BLL;
using Model;

public partial class ProductRepair_ManageRepair_AutoUnionforPackageProductSN : System.Web.UI.Page
{
    private PackageProduct pp;

    public ProductRepair_ManageRepair_AutoUnionforPackageProductSN()
    {
        pp = new PackageProduct();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.TextBox6.Focus();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string var_packagePrdouctSN = this.TextBox2.Text.Trim();
        string var_productTypeID = this.TextBox6.Text.Trim();
        string userID = User.Identity.Name;
        string str = "";
        if (!pp.IsvalidPackageProductSNtoUnion(var_packagePrdouctSN, out str))
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str + "');</script>");
        }
        else
        {
            if (!pp.IsvalidProductTypeIDtoUnion(var_productTypeID, out str))
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str + "');</script>");
            }
            else
            {
                PackageProductInfo ppi = new PackageProductInfo(var_packagePrdouctSN, "", var_productTypeID, userID, DateTime.Now);
                if (pp.AutoUnionforPackageProductSN(ppi))
                {
                    str = "自动关联成功！";
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str + "');</script>");
                    this.TextBox6.Text = "";
                    this.TextBox2.Text = "";
                }
                else
                {
                    str = "自动关联失败，请联系相关人员！";
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str + "');</script>");
                }
            }
        }
    }


    protected void Button4_Click(object sender, EventArgs e)
    {
        string var_packagePrdouctSN = this.TextBox4.Text.Trim();
        IList<PackageProductInfo> list = new List<PackageProductInfo>();
        PackageProductInfo ppi = pp.GetPackageProductbyPackageProductSN(var_packagePrdouctSN);
        if (!string.IsNullOrEmpty(ppi.PackageProductSN))
        {
            list.Add(ppi);
        }
        this.GridView2.DataSource = list;
        this.GridView2.DataBind();
    }

}
